<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<table border="1">
    <tr>
        <th>商品id</th><th>商品标题</th>
        <th>商品价格</th><th>商品销量</th>
        <th>操作</th>
    </tr>
    <tr v-for="p in products">
        <td>{{p.id}}</td>
        <td>{{p.title}}</td>
        <td>{{p.price}}</td>
        <td>{{p.saleCount}}</td>
        <td><a href="javascript:void(0)" @click="del(p.id)">删除</a>
            <a :href="'/update.html?id='+p.id">修改</a>
        </td>
    </tr>
</table>
<script src="js/vue.js"></script>
<script src="js/axios.min.js"></script>
<script>
    let v = new Vue({
        el:"table",
        data:{
            products:[{id:1,title:"xiaomi11",price:"1999",saleCount:"1000"},
                {id:2,title:"nova7",price:"2999",saleCount:"1900"},
                {id:3,title:"iphone13",price:"5999",saleCount:"2000"}]
        },
        methods:{
            findAll(){
                axios.get("/selectAll").then(function (response) {
                    v.products = response.data;
                });
            },
            del(id){
                axios.get("/delete?id="+id).then(function (response) {
                    alert("删除成功")
                    location.reload();
                });

            }
        },
        created:function(){
            axios.get("/selectAll").then(function (response) {
                v.products = response.data;
            });
        },
        mounted:function () {
           // this.findAll();
        }
    })
</script>
</body>
</html>